package com.example.springblog.config;

import com.example.springblog.model.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/*
* 设置统一异常处理
* */
@ControllerAdvice
@ResponseBody
public class ExceptionAdvice {
    //对异常进行统一处理，就不需要加上try-catch
    @ExceptionHandler
    public Result exceptionAdvice(Exception e){
        return Result.fail(-1,e.getMessage());
    }
}
